package com.springboot.cloud.seckill.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.springboot.cloud.common.web.entity.vo.SecKillMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author godyao
 * @date 2022/3/18
 */
@Service
@Slf4j
public class RabbitMqSecKillSender {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void sendForSecKillOrder(SecKillMessage secKillMessage) {
        try {
            rabbitTemplate.convertAndSend("secKillEx","direct.biz.secKill",new ObjectMapper().writeValueAsString(secKillMessage));
        } catch (JsonProcessingException e) {
            log.error("消息发送失败，msg={}", e.getLocalizedMessage());
        }
    }
}
